<template>
	<view class="pics">
		<scroll-view class="left" scroll-y="true" >
			<view v-for="(item,index) in cates" :key="item.id" :class="active===index? 'active':''" @click="getClass(index,item.id)">{{item.title}}</view>
		</scroll-view>
		<scroll-view scroll-y="true" class="right">
			<view @click="previewImage(item.img_url)" class="item" v-for="item in secondCate">
				<image :src="item.img_url"></image>
				<text>{{item.title}}</text>
			</view>
			<text v-if="secondCate.length===0">此社区暂无图片</text>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cates:[],
				active:0,
				secondCate:[],
			}
		},
		methods: {
			async getPicCate(){
				const res =await this.$myrequest({
					url:'/api/getimgcategory'
				})
				this.cates = res.data.message
				this.getClass(0,this.cates[0].id)
			},
			async getClass(index,id){
				this.active = index
				console.log(index)
				// 获取右侧的数据
				const res = await this.$myrequest({
					url:'/api/getimages/'+id
				});
				res.data.message.map((item)=>{item.img_url='https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fi1.hdslb.com%2Fbfs%2Farchive%2Fdbb2a85553b5c1e9ac606f863a840ed17724f49e.jpg&refer=http%3A%2F%2Fi1.hdslb.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1619418533&t=a2166ce1798dbf767d3bef02cc6aff8f'})
				this.secondCate = res.data.message
				console.log('图片获取完成')
			},
			previewImage(currentimage){
				const urls = this.secondCate.map(item=>item.img_url)
				uni.previewImage({
					current:currentimage,
					urls
				})
			}
		},
		onLoad() {
			this.getPicCate()
		},
	}
</script>

<style lang="scss">
page{
	height: 100%;
}
.pics{
	height: 100%;
	display: flex;
	.left{
		box-sizing: border-box;
		width: 80px;
		height: 100%;
		border-right: 1px solid #eee;
		view{
			height: 100rpx;
			line-height: 100rpx;
			color: #333;
			text-align: center;
			border: 1px solid #eee;
		}
	}
	.active{
		background-color: $market-color;
	}
	.right{
		margin: 10rpx;
		width: 565rpx;
		height: 100%;
		image{
			margin: 2px auto;
			border-radius: 2px;
		}
	}
}
</style>
